﻿var replaceArr=[["男","男人"],["女","女人"]];
var levelArr=[
["男人","女人"],
["马术","露营","徒步","水上","棒球","自行车","钓鱼","高尔夫","狩猎","保龄球","游泳","网球","跑步","派对","街舞"],
["贝雷","太阳","牛仔","披肩"]
];

function amazonUKId(keywords,v)
{
	var arr=new Array();
	if(v!=null)
	{
		for(var i=0;i<codeAmazonArr.length;i++)
		{
			if(codeAmazonArr[i].indexOf(v)>-1) arr.push(codeAmazonArr[i]);
		}
	}
	if(arr.length==0) arr=codeAmazonArr;
	var keysArr=keywords.split(",");
	//去重
	for(var i=0;i<keysArr.length;i++)
	{
		for(var j=i+1;j<keysArr.length;j++)
		{
			if(keysArr[i]==keysArr[j])
			{
				keysArr.splice(j,1);
			}
		}
	}
	//replace
	for(var i=0;i<keysArr.length;i++)
	{
		for(var j=0;j<replaceArr.length;j++)
		{
			if(keysArr[i]==replaceArr[j][0])
			{
				keysArr[i]=replaceArr[j][1];
				break;
			}
		}
	}
	//noise
	/*
	for(var i=0;i<noiseArr.length;i++)
	{
		if(keywords.indexOf(noiseArr[i][0])>-1 && keywords.indexOf(noiseArr[i][1])>-1)
		{
			for(var j=0;j<keysArr.length;j++)
			{
				if(keysArr[j].indexOf(noiseArr[i][0])>-1 || keysArr[j].indexOf(noiseArr[i][1])>-1 )
				{
					keysArr.splice(j,1);
				}
			}
		}
	}
	*/
	var timesArr=new Array();
	for(var i=0; i<arr.length;i++)
	{
		var times=0;
		for(var j=0;j<keysArr.length-1;j++)
		{
			if(arr[i][1].indexOf(keysArr[j])>-1)
			{
				var lp=jQuery.inArray( keysArr[j], levelArr[0]);
				if(jQuery.inArray( keysArr[j], levelArr[0])>-1) times=times+10;
				else if(jQuery.inArray( keysArr[j], levelArr[1])>-1) times=times+6;
				else if(jQuery.inArray( keysArr[j], levelArr[2])>-1) times=times+3;
				else times++;
			}
		}
		timesArr.push([arr[i][0],times]);
	}
	
	var s="";
	for(var i=0;i<timesArr.length;i++)
	{
		s+=timesArr[i][0]+","+timesArr[i][1]+"\n";
	}
	//$("#goodsTxt").html($("#goodsTxt").html()+"\n"+s);
	
	for(var i=0;i<timesArr.length;i++)
	{
		var maxtimes=timesArr[i][1],code=timesArr[i][0],pos=i;
		for(var j=i+1;j<timesArr.length;j++)
		{
			if(maxtimes<timesArr[j][1]) 
			{
				maxtimes=timesArr[j][1];
				code=timesArr[j][0];
				pos=j;
			}
		}
		if(pos!=i)
		{
			timesArr[pos][0]=timesArr[i][0];
			timesArr[pos][1]=timesArr[i][1];
			timesArr[i][0]=code;
			timesArr[i][1]=maxtimes;
		}
	}
	var ret="";
	for(var i=0;i<timesArr.length && i<2;i++)
	{
		if(ret!="") ret+=",";
		ret+=timesArr[i][0]
	}
	return ret;
}